﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Manager.FormAdd_Edit;
using Manager.App_Code;
using System.Linq;
using Manager.Common;
using System.Data.Linq;

namespace Manager.FormMain
{
    public partial class Frm_BarButton_LoaiPhong : DevExpress.XtraEditors.XtraForm
    {
        NewPearl_HotelDataContext db = new NewPearl_HotelDataContext();


        public Frm_BarButton_LoaiPhong()
        {
            InitializeComponent();
        }

        private void Frm_BarButton_LoaiPhong_Load(object sender, EventArgs e)
        {
            db.Refresh(RefreshMode.OverwriteCurrentValues, db.LoaiPhongs);
            gridControl1.DataSource = db.LoaiPhongs.ToList();
        }

        private void butThemMoi_Click(object sender, EventArgs e)
        {
            frm_LoaiPhong frmLoaiPhong = new frm_LoaiPhong();
            frmLoaiPhong.ShowDialog();
            Frm_BarButton_LoaiPhong_Load(sender, e);
        }

        private void butHieuChinh_Click(object sender, EventArgs e)
        {            
            int index = gridView1.FocusedRowHandle;
            var loaiPhong = gridView1.GetRow(index) as LoaiPhong;
            frm_LoaiPhong frmLoaiPhong = new frm_LoaiPhong(loaiPhong);
            frmLoaiPhong.ShowDialog();
            Frm_BarButton_LoaiPhong_Load(sender, e);
        }

        private void butXoa_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dr = MessageBox.Show("Bạn có muốn xóa không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (dr == DialogResult.OK)
                {
                    int index = gridView1.FocusedRowHandle;
                    var loaiPhong = gridView1.GetRow(index) as LoaiPhong;
                    db.LoaiPhongs.DeleteOnSubmit(loaiPhong);
                    MessageBox.Show("Xóa dữ liệu thành công!");
                    this.Frm_BarButton_LoaiPhong_Load(sender, e);
                }
            }
            catch (Exception ex)
            {
                Log.WriteLog("Frm_BarButton_LoaiPhong:butXoa_Click " + ex.Message + "\n" + ex.StackTrace);
                MessageBox.Show("Xóa dữ liệu thất bại!");
            }
        }
    }
}